package com.hq.door.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.hq.door.pojo.UserInfor;
import com.hq.door.service.IUserService;

@Controller
public class UserController {
	@Autowired
	private IUserService userService;

	// @Autowired的属性，spring 会扫描容器中的对象,如果发现名字相同的实例，则会自动注入

	@RequestMapping("/user/add")
	public ModelAndView addUser(UserInfor user) {
		System.out.println("-------UserController----addUser---");

		// 构建测试数据
		UserInfor user2 = new UserInfor();
		user2.setName("李四11");
		user2.setCode("0909090");
		// user
		userService.addUser(user2);

		return new ModelAndView("/user/success");
	}

	// json数据方式
	@RequestMapping("/user/testJson")
	@ResponseBody
	public UserInfor test3() {
		UserInfor user = new UserInfor();
		user.setName("admin");
		user.setCode("123");
		user.setAddress("广东");
		return user;
	}
}
